from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-11-27 14:03:27.872617
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 27, Nov, 2021
Time: 14:03:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -47.2522
Nobs: 488.000 HQIC: -47.7214
Log likelihood: 5576.12 FPE: 1.39009e-21
AIC: -48.0250 Det(Omega_mle): 1.15813e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.388524 0.083981 4.626 0.000
L1.Burgenland 0.094842 0.044765 2.119 0.034
L1.Kärnten -0.116026 0.022943 -5.057 0.000
L1.Niederösterreich 0.160106 0.093180 1.718 0.086
L1.Oberösterreich 0.122511 0.094623 1.295 0.195
L1.Salzburg 0.281970 0.048004 5.874 0.000
L1.Steiermark 0.019967 0.062214 0.321 0.748
L1.Tirol 0.107931 0.050026 2.157 0.031
L1.Vorarlberg -0.084297 0.044077 -1.912 0.056
L1.Wien 0.031832 0.084216 0.378 0.705
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.020985 0.186687 0.112 0.910
L1.Burgenland -0.051450 0.099512 -0.517 0.605
L1.Kärnten 0.036342 0.051001 0.713 0.476
L1.Niederösterreich -0.211093 0.207136 -1.019 0.308
L1.Oberösterreich 0.476157 0.210344 2.264 0.024
L1.Salzburg 0.310780 0.106711 2.912 0.004
L1.Steiermark 0.096154 0.138300 0.695 0.487
L1.Tirol 0.308409 0.111206 2.773 0.006
L1.Vorarlberg 0.008099 0.097982 0.083 0.934
L1.Wien 0.016346 0.187210 0.087 0.930
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.240925 0.042570 5.659 0.000
L1.Burgenland 0.093054 0.022692 4.101 0.000
L1.Kärnten -0.004120 0.011630 -0.354 0.723
L1.Niederösterreich 0.216594 0.047234 4.586 0.000
L1.Oberösterreich 0.158626 0.047965 3.307 0.001
L1.Salzburg 0.034170 0.024333 1.404 0.160
L1.Steiermark 0.028707 0.031537 0.910 0.363
L1.Tirol 0.074906 0.025358 2.954 0.003
L1.Vorarlberg 0.057089 0.022343 2.555 0.011
L1.Wien 0.102242 0.042690 2.395 0.017
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.180752 0.041384 4.368 0.000
L1.Burgenland 0.042868 0.022059 1.943 0.052
L1.Kärnten -0.011880 0.011306 -1.051 0.293
L1.Niederösterreich 0.143368 0.045917 3.122 0.002
L1.Oberösterreich 0.337215 0.046628 7.232 0.000
L1.Salzburg 0.097829 0.023655 4.136 0.000
L1.Steiermark 0.111564 0.030658 3.639 0.000
L1.Tirol 0.084600 0.024652 3.432 0.001
L1.Vorarlberg 0.054975 0.021720 2.531 0.011
L1.Wien -0.040909 0.041500 -0.986 0.324
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.182756 0.080255 2.277 0.023
L1.Burgenland -0.041984 0.042779 -0.981 0.326
L1.Kärnten -0.035956 0.021925 -1.640 0.101
L1.Niederösterreich 0.120883 0.089045 1.358 0.175
L1.Oberösterreich 0.176065 0.090424 1.947 0.052
L1.Salzburg 0.252651 0.045874 5.508 0.000
L1.Steiermark 0.076390 0.059454 1.285 0.199
L1.Tirol 0.130038 0.047806 2.720 0.007
L1.Vorarlberg 0.107494 0.042121 2.552 0.011
L1.Wien 0.035887 0.080479 0.446 0.656
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.073826 0.063506 1.163 0.245
L1.Burgenland 0.015816 0.033851 0.467 0.640
L1.Kärnten 0.050985 0.017349 2.939 0.003
L1.Niederösterreich 0.183757 0.070462 2.608 0.009
L1.Oberösterreich 0.341598 0.071553 4.774 0.000
L1.Salzburg 0.050052 0.036300 1.379 0.168
L1.Steiermark -0.009448 0.047046 -0.201 0.841
L1.Tirol 0.123896 0.037829 3.275 0.001
L1.Vorarlberg 0.057892 0.033331 1.737 0.082
L1.Wien 0.113085 0.063684 1.776 0.076
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185551 0.077210 2.403 0.016
L1.Burgenland 0.011601 0.041156 0.282 0.778
L1.Kärnten -0.060156 0.021093 -2.852 0.004
L1.Niederösterreich -0.118666 0.085667 -1.385 0.166
L1.Oberösterreich 0.220620 0.086994 2.536 0.011
L1.Salzburg 0.036020 0.044133 0.816 0.414
L1.Steiermark 0.270042 0.057198 4.721 0.000
L1.Tirol 0.488709 0.045992 10.626 0.000
L1.Vorarlberg 0.073375 0.040523 1.811 0.070
L1.Wien -0.103551 0.077426 -1.337 0.181
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.136857 0.085463 1.601 0.109
L1.Burgenland -0.013233 0.045555 -0.290 0.771
L1.Kärnten 0.064066 0.023347 2.744 0.006
L1.Niederösterreich 0.174307 0.094824 1.838 0.066
L1.Oberösterreich -0.075646 0.096293 -0.786 0.432
L1.Salzburg 0.222132 0.048851 4.547 0.000
L1.Steiermark 0.134287 0.063312 2.121 0.034
L1.Tirol 0.051184 0.050909 1.005 0.315
L1.Vorarlberg 0.142633 0.044855 3.180 0.001
L1.Wien 0.167084 0.085702 1.950 0.051
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.464285 0.047133 9.851 0.000
L1.Burgenland -0.001318 0.025124 -0.052 0.958
L1.Kärnten -0.013007 0.012876 -1.010 0.312
L1.Niederösterreich 0.175924 0.052296 3.364 0.001
L1.Oberösterreich 0.263151 0.053105 4.955 0.000
L1.Salzburg 0.018030 0.026941 0.669 0.503
L1.Steiermark -0.012134 0.034917 -0.348 0.728
L1.Tirol 0.068898 0.028076 2.454 0.014
L1.Vorarlberg 0.056765 0.024737 2.295 0.022
L1.Wien -0.018452 0.047265 -0.390 0.696
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.025961 0.089660 0.153443 0.136538 0.065116 0.080684 0.015329 0.207592
Kärnten 0.025961 1.000000 -0.037298 0.128667 0.047069 0.071657 0.457228 -0.082694 0.094303
Niederösterreich 0.089660 -0.037298 1.000000 0.272886 0.094449 0.256370 0.043404 0.142577 0.240970
Oberösterreich 0.153443 0.128667 0.272886 1.000000 0.186235 0.289071 0.159248 0.126719 0.171626
Salzburg 0.136538 0.047069 0.094449 0.186235 1.000000 0.120958 0.058171 0.109604 0.060231
Steiermark 0.065116 0.071657 0.256370 0.289071 0.120958 1.000000 0.132699 0.087060 0.005189
Tirol 0.080684 0.457228 0.043404 0.159248 0.058171 0.132699 1.000000 0.062327 0.128352
Vorarlberg 0.015329 -0.082694 0.142577 0.126719 0.109604 0.087060 0.062327 1.000000 -0.011187
Wien 0.207592 0.094303 0.240970 0.171626 0.060231 0.005189 0.128352 -0.011187 1.000000